<template>
	<view>
		<uv-tabbar v-if="!screen" iconSize="25px" customStyle="padding:5px" :value="tabbarValue" @change="change">
			<uv-tabbar-item v-for="(item,index) in tabbar" :key="item.name" v-show="!item.hide">
				<template v-slot:text>
					<uv-text align="center" style="display: flex;justify-content: center;align-items: center;" size="12"
						:text="item.name"></uv-text>
				</template>
				<template v-slot:active-icon>
					<uv-icon v-if="item.click!='my'" size="25"
						:name="'/static/index/svg/select/'+item.icon+'.svg'"></uv-icon>
					<el-image v-else style="width: 25px; height:25px;border-radius: 50%;" :src="vuex_user.portrait"
						fit="cover">
						<div slot="error" class="image-slot">
							<el-image :src="'/static/index/svg'+(index==tabbarValue?'/select':'')+'/'+item.icon+'.svg'"
								fit="fill"></el-image>
						</div>
					</el-image>
				</template>
				<template v-slot:inactive-icon>
					<uv-icon v-if="item.click!='my'" size="25" :name="'/static/index/svg/'+item.icon+'.svg'"></uv-icon>
					<el-image v-else style="width: 25px; height:25px;border-radius: 50%;" :src="vuex_user.portrait"
						fit="cover">
						<div slot="error" class="image-slot">
							<el-image
								:src="'/static/index/svg'+(index==tabbarValue?'/select':'')+'/'+item.icon+'.svg'"></el-image>
						</div>
					</el-image>
				</template>
			</uv-tabbar-item>
		</uv-tabbar>
	</view>
</template>

<script>
	// 引入
	import config from '@/common/config'
	export default {
		data() {
			return {
				tabbar: config.tabbar,
				tabbarsValue: '',
				routes: ''
			}
		},
		computed: {},
		created() {
			var pages = getCurrentPages() // 获取栈实例
			let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
			let currentPage = pages[pages.length - 1]['$page']['fullPath']; //当前页面路径(带参数)
			this.routes = pages[pages.length - 1]['$page']['route']; //当前页面路径(带参数)
			this.tabbarsValue = currentPage.split('/')[2];
		},
		methods: {
			change(e) {
				const tab = this.tabbar;
				// console.log('e', e, tab);
				for (let item in tab) {
					// if (e === tab[item].en) { 旧
					// 	this.routed(tab[item].url);
					// }
					this.$uv.vuex('tabbarValue', e);
					// console.log(tab[e].url, '/' + this.routes);
					if (tab[e].url && tab[e].url != ('/' + this.routes)) {
						this.routed(tab[e].url + '?type=' + tab[e].click);
					}
				}
			},
			routed(url) {
				uni.$uv.route({
					type: 'reLaunch',
					url: url,
				})
			}
		}
	}
</script>